/*
 * TouchPagerActivity.java
 * classes : com.ruint.lib.mediachooser.activity.TouchPagerActivity
 * @author ruint
 * V 1.0.0
 * Create at 2014-12-8 下午5:32:41
 */
package com.ruint.lib.mediachooser.activity;

import java.util.ArrayList;
import java.util.Random;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.widget.TextView;

import com.ruint.core.app.BaseActivity;
import com.ruint.core.utils.ui.ViewPagerUtils;
import com.ruint.corelib.R;
import com.ruint.lib.mediachooser.adapter.SectionPagerAdater;
import com.ruint.lib.mediachooser.core.MediaChooserConstants;

/**
 * com.ruint.lib.mediachooser.activity.TouchPagerActivity
 * 
 * @author ruint <br/>
 *         create at 2014-12-8 下午5:32:41
 */
public class TouchPagerActivity extends BaseActivity implements OnPageChangeListener {
  private ViewPager mViewPager;
  private TextView mIndexText;

  private SectionPagerAdater<String> mAdater;
  private ArrayList<String> mList;

  @Override
  protected int getLayoutResID() {
    return R.layout.activity_touch_pager;
  }

  @Override
  protected void pre4Create(Bundle savedInstanceState) {
  }

  @Override
  protected void findViews() {
    mViewPager = findView(mViewPager, R.id.touch_pager);
    mIndexText = findView(mIndexText, R.id.touch_pager_index);
  }

  @Override
  protected void handleRelevancy() {
    mAdater = new SectionPagerAdater<String>(getSupportFragmentManager());
    mViewPager.setOnPageChangeListener(this);
    ViewPagerUtils.setPagerTransformer(mViewPager, ViewPagerUtils.DefaultTransformer);
  }

  @Override
  protected void onLoadingData() {
    mList = getIntent().getStringArrayListExtra(MediaChooserConstants.MEDIA_SELECTED_LIST);
    mViewPager.setAdapter(mAdater);
    mAdater.build(mList);
  }

  @Override
  public void onPageScrollStateChanged(int position) {
  }

  @Override
  public void onPageScrolled(int position, float arg1, int arg2) {
  }

  @Override
  public void onPageSelected(int position) {
    if (mList != null) {
      mIndexText.setText(position + "/" + mList.size());
    }
    ViewPagerUtils.setPagerTransformer(mViewPager, new Random().nextInt(15));
  }
}
